package com.aaa.exceptions;

import com.aaa.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author : luoBo
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    // 处理自定义异常
    @ExceptionHandler(CustomException.class)
    public Result<Object> handleCustomException(CustomException ex) {
        return  Result.failure(ex.getErrorMessage());
    }

    // 处理其他异常（如 NullPointerException、IllegalArgumentException 等）
    @ExceptionHandler(Exception.class)
    public Result<Object> handleGlobalException(Exception ex) {
        return Result.failure(ex.getMessage());
    }
}
